import React ,{useState}from 'react';
import useCityReducer from '../Reducers';
import { useNavigate } from 'react-router-dom';
const Index = () => {
    const navtigate=useNavigate()
    const [state,dispatch] =useCityReducer();
    const [citys] = useState(["上海","武汉","成都","杭州","北京"])
    const handleCity=(val)=>{
        dispatch({
            type:"handleCity",
            value:val
        })
        navtigate(-1)
    }
    return (
        <div>
            {citys.map(item=>{
                return(
                    <button key={item} onClick={()=>handleCity(item)}>{item}</button>
                )
            })}
        </div>
    );
}

export default Index;
